package com.szqhyxj.youxiangju.biz.creditCardEvaluation.evaluationRecord;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.szqhyxj.youxiangju.BaseActivity;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.creditCardEvaluation.CreditCardEcaluationActivity;
import com.szqhyxj.youxiangju.biz.web.WebActivity;
import com.szqhyxj.youxiangju.sys.components.NavigationBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by leung on 2018/11/10.
 */

public class EvaluationRecordActivity extends BaseActivity implements NavigationBar.NavigationBarListener, EvaluationRecordContract.View, EvaluationRecordAdapter.IStartActivityListener{

    @BindView(R.id.navigationBar)
    NavigationBar navigationBar;
    @BindView(R.id.recordList)
    ListView recordList;
    EvaluationRecordPresernter presernter;
    EvaluationRecordAdapter adapter;
    List<RowsItem> rowlist = new ArrayList<>();
    @BindView(R.id.none)
    LinearLayout none;

    public static void start(Activity activity){
        Intent intent = new Intent();
        intent.setClass(activity, EvaluationRecordActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_evaluation_record);
        ButterKnife.bind(this);
        navigationBar.setNavigationBarListener(this);
        presernter = new EvaluationRecordPresernter(this);
        presernter.init(1);
        adapter = new EvaluationRecordAdapter(this, rowlist);
        recordList.setAdapter(adapter);
        adapter.setListener(this);
    }

    @Override
    public void navigationLeft(){
        CreditCardEcaluationActivity.start(this);
    }

    @Override
    public void navigationRight(){
    }

    @Override
    public void showList(List<RowsItem> list){
        if(list.size() == 0){
            none.setVisibility(View.VISIBLE);
            recordList.setVisibility(View.GONE);
        }else {
            none.setVisibility(View.GONE);
            recordList.setVisibility(View.VISIBLE);
        }
        rowlist.clear();
        rowlist.addAll(list);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onStartActivityListener(String url){
        WebActivity.start(this, "测评结果", url);
    }
}
